@extends('layouts.admin')

@section('title', '应用管理')

@section('content')
    <div class="console-title">
        <a href="{{admin_url('app/newapp')}}" class="float-right">
            <span class="btn btn-primary">添加应用</span>
        </a>
        <h2>应用管理->应用列表</h2>
    </div>
    <div class="content-div">
        <form method="post" id="listForm" autocomplete="off">
            @csrf
            <input type="hidden" name="eventType" value="" id="J_eventType">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="dsxui-listtable">
                <thead>
                <tr>
                    <th width="40"><input type="checkbox" class="checkmark" data-action="checkall"></th>
                    <th width="60">ID</th>
                    <th>应用名称</th>
                    <th>ppId</th>
                    <th>APPSecret</th>
                    <th>版本</th>
                    <th>网址</th>
                    <th>状态</th>
                    <th width="60">编辑</th>
                </tr>
                </thead>
                <tbody id="mainbody">
                @foreach($items as $item)
                    <tr>
                        <td><input title="" type="checkbox" class="checkmark" name="items[]" value="{{$item['id']}}"></td>
                        <td>{{$item['id']}}</td>
                        <td>{{$item['name']}}</td>
                        <td>{{$item['appid']}}</td>
                        <td>{{$item['secret']}}</td>
                        <td>{{$item['version']}}</td>
                        <td>{{$item['url']}}</td>
                        <td>{{$item['state'] ? '使用中' : '已停用'}}</td>
                        <td><a href="{{admin_url('app/newapp?id='.$item['id'])}}">编辑</a></td>
                    </tr>
                @endforeach
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="10" class="btn-group-sm">
                        <label><input type="checkbox" class="checkmark" data-action="checkall"> 全选</label>
                        <button type="button" class="btn btn-default btn-action" id="delete" disabled="disabled">删除</button>
                        <button type="button" class="btn btn-default btn-action" id="enable" disabled="disabled">启用</button>
                        <button type="button" class="btn btn-default btn-action" id="disable" disabled="disabled">停用</button>
                        <button type="button" class="btn btn-default" data-action="refresh">刷新</button>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
    <script type="text/javascript">
        $(function () {
            $(document).on('click', function () {
                if ($(".checkmark:checked").length === 0){
                    $(".btn-action").disable();
                } else {
                    $(".btn-action").enable();
                }
            });
            function submitForm(eventType){
                $("#J_eventType").val(eventType);
                $("#listForm").ajaxSubmit({
                    dataType:'json',
                    beforeSend:function () {
                        DSXUI.showSpinner();
                    },success:function (response) {
                        setTimeout(function () {
                            DSXUI.hideSpinner();
                            if (response.errcode) {
                                DSXUI.error(response.errmsg);
                            } else {
                                DSXUtil.reFresh();
                            }
                        }, 500);
                    }
                });
            }
            $("#delete").on('click', function () {
                DSXUI.showConfirm('删除确认', '你确认要删除所选应用吗?', function () {
                    submitForm('delete');
                });
            });
            $("#enable").on('click', function () {
                submitForm('enable');
            });
            $("#disable").on('click', function () {
                submitForm('disable');
            });
        });
    </script>
@stop
